// index.js
import Page from '../common/page';
// 获取应用实例
const app = getApp()
const getLessonListUrl = app.require('config').getLessonListUrl;
const https = app.require('/utils/httpTools');

Page({
  data: {
    isNull: true,
    lesson_list: [],
    scrollHeigh: app.data.windows_height
  },

  onLoad() {
    // 判断跳转页面参数，判断用户信息后转向
    // 判断微信是否授权，判断当前用户是否绑定VK帐号
    this.getLessonList();
  },

  selectBook(event) {
    wx.navigateTo({
      url: '/pages/select-books/select-books',
    })
  },

  openLessonTap(event) {
    console.info(event.currentTarget.dataset.id);
  },

  getLessonList() {
    var self = this;
    https.get(
      getLessonListUrl,
      {
        "code": "admin",
        "password": "123456"
      }
    ).then(rs => {
      var that = self;
      that.setData({ lesson_list: rs });
    }).catch(err => {
      console.log("error:", err);
      // 接口失败操作
      wx.showToast({
        title: err.errMsg || "服务异常，请稍后重试！",
        icon: 'error',
        duration: 2000
      })
    })
  },

  onPullDownRefresh() {
    //下拉刷新demo，已设定时器。实际编码手动控制stop
    wx.startPullDownRefresh(
      {
        success: function () {
          console.log('开史 succccc')
        },
        fail: function () {
          console.log('开史 faillll')
        },
        complete: function () {
          console.log('开史 compppp')
        }
      }
    );
    setTimeout(function () {
      wx.stopPullDownRefresh(
        {
          success: function () {
            console.log('succccc')
          },
          fail: function () {
            console.log('faillll')
          },
          complete: function () {
            console.log('compppp')
          }
        }
      );
    }, 2000, null);
  },

  onReachBottom: function () {
    console.log('i am loading')
  },

  onShow: function () {
    console.log('主页面')
    this.getTabBar().init();
  },

  tryAgain: function () {
    this.setData({
      isNull: false
    });
  },


});